class Solution {
public:
    int divide(int dividend, int divisor) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		long long a = dividend;
		long long b = divisor;
		bool sign = (a < 0 && b > 0) || (a > 0 && b < 0);
		if (a < 0) {
			a = -a;
		}
		if (b < 0) {
			b = -b;
		}
		long long c = 0;
		while (a >= b) {
			int shift = 0;
			while (a >= (b << (shift + 1))) {
				++shift;
			}
			c += 1L << shift;
			a -= b << shift;
		}
		return sign ? static_cast<int>(-c) : static_cast<int>(c);
    }
};